require(PBSadmb)
source("adfunctions.r")

mod1<-readList("..\\arc\\mod1_r.dat")
mod2<-readList("..\\arc\\mod2_r.dat")
mod3<-readList("..\\arc\\mod3_r.dat")
mod4<-readList("..\\arc\\mod4_r.dat")
mod5<-readList("..\\arc\\mod5_r.dat")
mod6<-readList("..\\arc\\mod6_r.dat")
mod7<-readList("..\\arc\\mod7_r.dat")

pdf("..\\results\\allfigs.pdf",width=9, height=7)
for (i in 1:7){
  y<-paste("mod",i,sep="")
  print(y)
  mod<-get(y)
  p.rec.hist(mod,main=paste("Model",i),ylab="Age 2 recruitment",fy=1970,ly=2010)
}
dev.off()

pdf("..\\results\\selectivity.pdf",width=9, height=7)
Mntns(mod4,"Model 4")
Mntns_srv(mod4,"Model 4")
Mntns_srv2(mod4,"Model 4")
Mntns(mod5,"Model 5")
Mntns(mod6,"Model 6")
dev.off()

pdf("..\\results\\indices.pdf",width=9, height=7)
  p.rec.hist(mod4,ylab="Age 2 recruitment",fy=1970,ly=2010)
  Indices(mod1,"Model 1")
  CatchFit(mod4,"Model 4") 
dev.off()
dev.off()

# recruitment hist w/ errors
Mntns(mod1,"Model 1")

# show projections
pdf("..\\results\\proj.pdf",width=9, height=7)
  plt_proj(mod4)
  plt_proj(mod5)
  plt_proj(mod6)
  plt_proj(mod2)
  plt_proj(mod3)
  plt_proj(mod4)
dev.off()
# show fit to catch biomass
# show spawning biomass relative to population with no fishing
spwn_ratio(mod1) 
mod1$SSB_NoFishR[42,]
mod2$SSB_NoFishR[42,]
mod3$SSB_NoFishR[42,]
# example of writing multiple plots to pdf file:
pdf("..\\results\\agefits1.pdf",width=9, height=7)
  AgeFits(mod4,f=1)
  AgeFits(mod4,f=2)
  AgeFits(mod4,f=3)
  AgeFits(mod4,f=4)
  AgeFitsSrv(mod4,f=1)
  AgeFitsSrv(mod4,f=4)
dev.off()

# another example of writing multiple plots to pdf file:
pdf("..\\results\\indices.pdf",width=9, height=7)
    Indices(mod1a,"Model 1a")
    Indices(mod1b,"Model 1b")
    Indices(mod1c,"Model 1c")
    Indices(mod2,"Model 2")
    Indices(mod3,"Model 3")
    Indices(mod4,"Model 4")
    Indices(mod5,"Model 5")
dev.off()

pdf("..\\results\\selectivity.pdf",width=9, height=7)
Mntns(mod1a,"Model 1a")
Mntns(mod1b,"Model 1b")
Mntns(mod1c,"Model 1c")
Mntns(mod2 ,"Model 2")
Mntns(mod3 ,"Model 3")
Mntns(mod4 ,"Model 4")
Mntns(mod5 ,"Model 5")
dev.off()

Mntns_srv(mod1c,"Model 1c")

# Stock recruitment curve
 p.stock.rec(mod4)
 p.stock.rec(mod1)
# recruitment hist w/ errors
 p.rec.hist(mod1c,ylab="Age 2 recruitment",fy=1970,ly=2010)

# Fishing mortality 
 p.full.f(mod1,f=2)

# sample sizes
 p.eff.n(mod1,typ="f")
 p.eff.n(mod1,typ="f",f=2)
 p.eff.n(mod1,typ="f",f=3)
 p.eff.n(mod1,typ="f",f=4)

# spawning biomass and last year's estimates 
 p.biom.pol(mod4,typ="TB")
 lines(mod2$TotBiom[,1],mod2$TotBiom[,2],lty=3,lw=3)
 lines(mod3$TotBiom[,1],mod3$TotBiom[,2],lty=4,lw=3)
 lines(mod4$TotBiom[,1],mod4$TotBiom[,2],lty=3,lw=3)
 lines(mod7$TotBiom[,1],mod4$TotBiom[,2],lty=2,lw=3,col=red)

 lines(mod1a$TotBiom[,1],mod1a$TotBiom[,2],lty=3,lw=3)

# Survey fit
 p.sur.stk(mod1,f=8)

# Rec
 p.biom.stk(mod1,typ="R")

mod1a<- readList("arc/mod1a_r.dat")
mod1b<- readList("arc/mod1b_r.dat")
mod1c<- readList("arc/mod1c_r.dat")
mod2 <- readList("arc/mod2_r.dat")
mod3 <- readList("arc/mod3_r.dat")
mod4 <- readList("arc/mod4_r.dat")
mod5 <- readList("arc/mod5_r.dat")

# Numbers at age
 p.bub.age(mod1,siz=1e7)
